#ifndef LabviewRecoProcessor_h
#define LabviewRecoProcessor_h 1

#include <marlin/Processor.h>

#include "lccd.h"
#include "lccd/IConditionsChangeListener.hh"

#include "E4DMapper.hh"

#include "Mapper.hh"
#include "MappedContainer.hh"
#include "SiPMCalibrations.hh"

using namespace marlin;

namespace CALICE {
  
  /** Processor for reading Labview raw collection and EPT Mapper from database.   
   *  It processes the input data to create the LCIO EPTCalorimeter_Hits collections
   *  @author: S. Lu (DESY Hamburg)
   *  @date Aug 20 2012
   */
  
  class LabviewRecoProcessor : public Processor, public lccd::IConditionsChangeListener {
    
  public:

    LabviewRecoProcessor();
    ~LabviewRecoProcessor();

    /** Implementation of new Processor 
      * returns pointer to processor  
      */
    virtual Processor* newProcessor() { return new LabviewRecoProcessor;}

    /* Called at the begin of the job before anything is read.
     */
    virtual void init(); 

    /* Called for every event.
     */
    virtual void processEvent( LCEvent * evt ) ;

    /* Called after data processing for clean up.
     */
    virtual void end();
      /* callback function for the condition changes
     */
    virtual void conditionsChanged(LCCollection *col);

  private:

    void updateE4DMapper();
    void updateMapping();
    void updatePedestal();

    //static std::map<std::string, MappedContainer<SiPMCalibrations>* > _SiPMCalibrationsContainerMap;
    //MappedContainer<SiPMCalibrations>* _container;
    std::vector<SiPMCalibrations*> _allCalibrations;

    bool _E4DMapperChanged;
    bool _pedestalChanged;

    LCCollection *_E4DMapperCol;
    LCCollection *_pedestalCol;

  protected:
    
    /** The string variable to access the inputcollection.
     */
    std::string _inputColName;

    /** The string variable to access the E4DMapper collection.
     */
    std::string _E4DMapperColName;

    /** The string variable to access the pedestal collection.
     */
    std::string _pedestalColName;

    /**<name of the output AHC hit collection
     */
    std::string _ahcHitOutputColName;


    /** The E4Dmapper variable for EPT Mapping which read from database or text file.
      */
    E4DMapper _e4dmapping; 

    std::vector<SimpleValue> _pedestal;

    //    const Mapper* _mapper;
    const Mapper* _mapper;
    unsigned int _mapperVersion;

  
  };
 
} // end namespace CALICE 

#endif
